package com.neusoft.mapper;

import com.neusoft.po.Credit;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CreditMapper {

    @Select("select * from credit_copy where userId=#{userId} and deleted=0")
    public List<Credit> getTotalCreditByUserId(String userId);

    @Select("select * from credit where userId=#{userId}")
    public List<Credit> getCreditByUserId(String userId);

    @Select("select * from credit where userId=#{userId} and channelType=#{channelType}")
    public List<Credit> getCreditByUserIdAndChannelType(String userId, int channelType);

    @Insert("insert into credit values(null, #{userId}, #{channelType}, #{num}, #{createTime}, #{expiredTime})")
    @Options(useGeneratedKeys = true, keyProperty = "creditId", keyColumn = "creditId")
    public int insertCredit(Credit credit);

    @Insert("insert into credit_copy values(null, #{userId}, #{channelType}, #{num}, #{createTime}, #{expiredTime}, 0)")
    @Options(useGeneratedKeys = true, keyProperty = "creditId", keyColumn = "creditId")
    public int insertCreditCopy(Credit credit);

    @Update("update credit_copy set deleted=1 where creditId=#{creditId}")
    public int deleteCreditCopyByCreditId(int creditId);

    @Update("update credit_copy set num=#{leftNum} where creditId=#{creditId}")
    public int updateCreditCopyByCreditId(@Param("creditId") int creditId, @Param("leftNum") int leftNum);
}
